package com.dianping.cat.configuration.server.transform;

import com.dianping.cat.configuration.server.IEntity;
import com.dianping.cat.configuration.server.IVisitor;
import com.dianping.cat.configuration.server.entity.ConsumerConfig;
import com.dianping.cat.configuration.server.entity.Domain;
import com.dianping.cat.configuration.server.entity.HarfsConfig;
import com.dianping.cat.configuration.server.entity.HdfsConfig;
import com.dianping.cat.configuration.server.entity.LongConfig;
import com.dianping.cat.configuration.server.entity.Property;
import com.dianping.cat.configuration.server.entity.Server;
import com.dianping.cat.configuration.server.entity.ServerConfig;
import com.dianping.cat.configuration.server.entity.StorageConfig;
import java.util.Stack;

public class DefaultMerger
  implements IVisitor
{
/*  19 */   private Stack<Object> m_objs = new Stack();

  private ServerConfig m_serverConfig;


  public DefaultMerger() {}

  public DefaultMerger(ServerConfig serverConfig) {
/*  27 */     this.m_serverConfig = serverConfig;
/*  28 */     this.m_objs.push(serverConfig);
  }


  public ServerConfig getServerConfig() { return this.m_serverConfig; }



  protected Stack<Object> getObjects() { return this.m_objs; }


  public <T> void merge(IEntity<T> to, IEntity<T> from) {
/*  40 */     this.m_objs.push(to);
/*  41 */     from.accept(this);
/*  42 */     this.m_objs.pop();
  }


/*  46 */   protected void mergeConsumer(ConsumerConfig to, ConsumerConfig from) { to.mergeAttributes(from); }



/*  50 */   protected void mergeDomain(Domain to, Domain from) { to.mergeAttributes(from); }



/*  54 */   protected void mergeHarfs(HarfsConfig to, HarfsConfig from) { to.mergeAttributes(from); }



/*  58 */   protected void mergeHdfs(HdfsConfig to, HdfsConfig from) { to.mergeAttributes(from); }



/*  62 */   protected void mergeLongConfig(LongConfig to, LongConfig from) { to.mergeAttributes(from); }



/*  66 */   protected void mergeProperty(Property to, Property from) { to.mergeAttributes(from); }



/*  70 */   protected void mergeServer(Server to, Server from) { to.mergeAttributes(from); }



/*  74 */   protected void mergeServerConfig(ServerConfig to, ServerConfig from) { to.mergeAttributes(from); }



  protected void mergeStorage(StorageConfig to, StorageConfig from) { to.mergeAttributes(from); }



  public void visitConsumer(ConsumerConfig from) {
/*  83 */     ConsumerConfig to = (ConsumerConfig)this.m_objs.peek();

/*  85 */     mergeConsumer(to, from);
/*  86 */     visitConsumerChildren(to, from);
  }

  protected void visitConsumerChildren(ConsumerConfig to, ConsumerConfig from) {
/*  90 */     if (from.getLongConfig() != null) {
/*  91 */       LongConfig target = to.getLongConfig();

/*  93 */       if (target == null) {
/*  94 */         target = new LongConfig();
/*  95 */         to.setLongConfig(target);
      }

/*  98 */       this.m_objs.push(target);
/*  99 */       from.getLongConfig().accept(this);
/* 100 */       this.m_objs.pop();
    }
  }


  public void visitDomain(Domain from) {
/* 106 */     Domain to = (Domain)this.m_objs.peek();

/* 108 */     mergeDomain(to, from);
/* 109 */     visitDomainChildren(to, from);
  }


  protected void visitDomainChildren(Domain to, Domain from) {}


  public void visitHarfs(HarfsConfig from) {
/* 117 */     HarfsConfig to = (HarfsConfig)this.m_objs.peek();

/* 119 */     mergeHarfs(to, from);
/* 120 */     visitHarfsChildren(to, from);
  }


  protected void visitHarfsChildren(HarfsConfig to, HarfsConfig from) {}


  public void visitHdfs(HdfsConfig from) {
/* 128 */     HdfsConfig to = (HdfsConfig)this.m_objs.peek();

/* 130 */     mergeHdfs(to, from);
/* 131 */     visitHdfsChildren(to, from);
  }


  protected void visitHdfsChildren(HdfsConfig to, HdfsConfig from) {}


  public void visitLongConfig(LongConfig from) {
/* 139 */     LongConfig to = (LongConfig)this.m_objs.peek();

/* 141 */     mergeLongConfig(to, from);
/* 142 */     visitLongConfigChildren(to, from);
  }

  protected void visitLongConfigChildren(LongConfig to, LongConfig from) {
/* 146 */     for (Domain source : from.getDomains().values()) {
/* 147 */       Domain target = to.findDomain(source.getName());

/* 149 */       if (target == null) {
/* 150 */         target = new Domain(source.getName());
/* 151 */         to.addDomain(target);
      }

/* 154 */       this.m_objs.push(target);
/* 155 */       source.accept(this);
/* 156 */       this.m_objs.pop();
    }
  }


  public void visitProperty(Property from) {
/* 162 */     Property to = (Property)this.m_objs.peek();

/* 164 */     mergeProperty(to, from);
/* 165 */     visitPropertyChildren(to, from);
  }


  protected void visitPropertyChildren(Property to, Property from) {}


  public void visitServer(Server from) {
/* 173 */     Server to = (Server)this.m_objs.peek();

/* 175 */     mergeServer(to, from);
/* 176 */     visitServerChildren(to, from);
  }

  protected void visitServerChildren(Server to, Server from) {
/* 180 */     for (Property source : from.getProperties().values()) {
/* 181 */       Property target = to.findProperty(source.getName());

/* 183 */       if (target == null) {
/* 184 */         target = new Property(source.getName());
/* 185 */         to.addProperty(target);
      }

/* 188 */       this.m_objs.push(target);
/* 189 */       source.accept(this);
/* 190 */       this.m_objs.pop();
    }

/* 193 */     if (from.getStorage() != null) {
/* 194 */       StorageConfig target = to.getStorage();

/* 196 */       if (target == null) {
/* 197 */         target = new StorageConfig();
/* 198 */         to.setStorage(target);
      }

/* 201 */       this.m_objs.push(target);
/* 202 */       from.getStorage().accept(this);
/* 203 */       this.m_objs.pop();
    }

/* 206 */     if (from.getConsumer() != null) {
/* 207 */       ConsumerConfig target = to.getConsumer();

/* 209 */       if (target == null) {
/* 210 */         target = new ConsumerConfig();
/* 211 */         to.setConsumer(target);
      }

/* 214 */       this.m_objs.push(target);
/* 215 */       from.getConsumer().accept(this);
/* 216 */       this.m_objs.pop();
    }
  }


  public void visitServerConfig(ServerConfig from) {
/* 222 */     ServerConfig to = (ServerConfig)this.m_objs.peek();

/* 224 */     mergeServerConfig(to, from);
/* 225 */     visitServerConfigChildren(to, from);
  }

  protected void visitServerConfigChildren(ServerConfig to, ServerConfig from) {
/* 229 */     for (Server source : from.getServers().values()) {
/* 230 */       Server target = to.findServer(source.getId());

/* 232 */       if (target == null) {
/* 233 */         target = new Server(source.getId());
/* 234 */         to.addServer(target);
      }

/* 237 */       this.m_objs.push(target);
/* 238 */       source.accept(this);
/* 239 */       this.m_objs.pop();
    }
  }


  public void visitStorage(StorageConfig from) {
/* 245 */     StorageConfig to = (StorageConfig)this.m_objs.peek();

/* 247 */     mergeStorage(to, from);
/* 248 */     visitStorageChildren(to, from);
  }

  protected void visitStorageChildren(StorageConfig to, StorageConfig from) {
/* 252 */     for (HdfsConfig source : from.getHdfses().values()) {
/* 253 */       HdfsConfig target = to.findHdfs(source.getId());

/* 255 */       if (target == null) {
/* 256 */         target = new HdfsConfig(source.getId());
/* 257 */         to.addHdfs(target);
      }

/* 260 */       this.m_objs.push(target);
/* 261 */       source.accept(this);
/* 262 */       this.m_objs.pop();
    }

/* 265 */     for (HarfsConfig source : from.getHarfses().values()) {
/* 266 */       HarfsConfig target = to.findHarfs(source.getId());

/* 268 */       if (target == null) {
/* 269 */         target = new HarfsConfig(source.getId());
/* 270 */         to.addHarfs(target);
      }

/* 273 */       this.m_objs.push(target);
/* 274 */       source.accept(this);
/* 275 */       this.m_objs.pop();
    }

/* 278 */     for (Property source : from.getProperties().values()) {
/* 279 */       Property target = to.findProperty(source.getName());

/* 281 */       if (target == null) {
/* 282 */         target = new Property(source.getName());
/* 283 */         to.addProperty(target);
      }

/* 286 */       this.m_objs.push(target);
/* 287 */       source.accept(this);
/* 288 */       this.m_objs.pop();
    }
  }
}


/* Location:              /Users/hanfei/Documents/apache-tomcat-9.0.24/webapps/cat/WEB-INF/lib/cat-core-3.0.0.jar!/com/dianping/cat/configuration/server/transform/DefaultMerger.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       1.0.7
 */